package com.chaoyi.controller.ifs;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.chaoyi.model.Topic;
import com.chaoyi.service.TopicService;
import com.chaoyi.util.PageUtil;

@Controller
@RequestMapping("/topicIfs")
public class TopicIfsController {
	@Resource
	private TopicService topicService;
	
	@RequestMapping("getTopicIList")
	@ResponseBody
	public JSONObject getTopicIList(HttpServletRequest request, HttpServletResponse response){
		response.setHeader("Access-Control-Allow-Origin", "*");
		JSONObject json = new JSONObject();
		int page = 0;
		int pageSize = 0;
		int topicType = 1;
		try {
			page = Integer.parseInt(request.getParameter("page"));
			pageSize = Integer.parseInt(request.getParameter("pageSize"));
		    topicType = Integer.parseInt(request.getParameter("topicType"));
		} catch (Exception e) {
			page = 1;
			pageSize = 20;
		}
		if (page < 0) {
			page = 1;
		}
		if (pageSize < 0) {
			pageSize = 20;
		}
		List<Topic> list = topicService.findList(PageUtil.getOffset(page, pageSize)+"",pageSize+"",topicType+"");
		json.put("rows", list);
		return json;
	}
	
}
